/*
 * p4293.cpp
 *
 *  Created on: 2013-10-22
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
int g[505][505], mp[505][505], val[505], dp[505], n, N, A[505], B[505];
int DP(int i)
{
	int &ans = dp[i];
	if (ans > 0)
		return ans;
	ans = val[i];
	for (int j = 1; j <= n; j++)
		if (g[i][j])
			ans = max(ans, DP(j) + val[i]);
	return ans;
}
int main()
{
	while (scanf("%d", &N) != EOF)
	{
		memset(g, 0, sizeof(g));
		memset(mp, 0, sizeof(mp));
		memset(val, 0, sizeof(val));
		memset(dp, 0, sizeof(dp));
		n = 0;
		for (int i = 1; i <= N; i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			if (a + b >= N)
				continue;
			int x = a + 1;
			int y = N - b;
			if (!mp[x][y])
			{
				n++;
				mp[x][y] = n;
				A[n] = x;
				B[n] = y;
			}
			val[mp[x][y]] = min(y - x + 1, val[mp[x][y]] + 1);
		}
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				if (B[i] < A[j])
					g[i][j] = 1;

		for (int i = 1; i <= n; i++)
			g[0][i] = 1;
		printf("%d\n", DP(0));
	}
	return 0;
}
